// 用户模块
import { setItem, getItem } from '@/utils/storage'
import { getUserInfo } from '@/api/user'
const TOKEN_KEY = 'SHOP_TOKEN'
const USER_KEY = 'SHOP_USER'
export default {
  namespaced:true,
  state:{
    token: getItem(TOKEN_KEY) || {},
    userInfo:getItem(USER_KEY) || {},
  },
  mutations:{
    setToken(state, data) {
      state.token = data
      setItem(TOKEN_KEY, data)
    },
    setUser(state,data){
      state.userInfo = data
      setItem(USER_KEY, data)
    },
    quit(state) {
      state.token = {}
      state.userInfo = {}
      setItem(TOKEN_KEY, {})
      setItem(USER_KEY, {})
    }
  },
  actions:{
    async getUserInfo(context){
      let data = await getUserInfo()
      context.commit('setUser',data)
    }
  }
}